﻿#include "settingoperate.h"
#include "ui_settingoperate.h"

SettingOperate::SettingOperate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingOperate)
{
    ui->setupUi(this);

    initWindowsUnits();
}

SettingOperate::~SettingOperate()
{
    delete ui;
}

void SettingOperate::initWindowsUnits()
{
    ui->le_ip->setEnabled(false);
    ui->le_port->setEnabled(false);
    ui->le_ip->setText(GlobalVars::g_localConfig.readIpAdress());
    ui->le_port->setText(GlobalVars::g_localConfig.readPort());
}

void SettingOperate::on_pb_close_clicked()
{
    this->close();
}

void SettingOperate::on_pb_modify_clicked()
{
    if (ui->pb_modify->text() == "修改")
    {
        ui->pb_modify->setText("确定");
        ui->le_ip->setEnabled(true);
        ui->le_port->setEnabled(true);
    }else
    {
        ui->pb_modify->setText("修改");
        ui->le_ip->setEnabled(false);
        ui->le_port->setEnabled(false);
        GlobalVars::g_localConfig.writeIpAdress(ui->le_ip->text());
        GlobalVars::g_localConfig.writePort(ui->le_port->text());
    }
}
